﻿using System;
using System.Windows.Forms;
using JetBrains.Annotations;
using Kaleida.ServiceMonitor.Model.Runtime;

namespace Kaleida.ServiceMonitor.UI
{
    public partial class ModulePanelControl : UserControl
    {
        private bool isNormal = true;
        private readonly CompiledScriptModule module;
        
        public ModulePanelControl(CompiledScriptModule module, Control content)
        {
            this.module = module;
            InitializeComponent();

            content.Dock = DockStyle.Fill;
            pnlContent.Controls.Add(content);

            AddMouseHandlers(pnlContent);
        }

        private void AddMouseHandlers(Control control)
        {
            control.DoubleClick += Control_DoubleClick;
            
            foreach (Control childControl in control.Controls)
                AddMouseHandlers(childControl);
        }

        private void Control_DoubleClick(object sender, EventArgs e)
        {
            if (isNormal)
                ZoomIn();
            else
                ZoomNormal();
        }

        [NotNull]
        public CompiledScriptModule Module
        {
            get { return module; }
        }

        public void ZoomIn()
        {
            Dock = DockStyle.Fill;
            BringToFront();

            isNormal = false;
        }

        public void ZoomNormal()
        {
            Dock = DockStyle.None;

            isNormal = true;
        }
    }
}
